<?php
/**
 * file created on 25/ott/06
 *
 * jaco_at_pixeldump_dot_org
 */


/**
 * reads data
 * fills an associative array with product info data
 */
function read_productInfo_data($tagData = ""){

	$pid = array();

	return $pid;
}

/**
 * reads data
 * return an associative array with f9 class name definitions tag
 */
function read_classNameContainer_data($tagData = ""){

	$cncd = array();
	$cncd = read_tag_header_data(substr($tagData, 0, 10));
	$ofst = $cncd["tagSL"];

	$cncd["classCount"] = ui16dec(substr($tagData, $ofst, 2));
	$ofst += 2;
	$cncd["objIDs"] = array();
	$cncd["classNames"] = array();

	for($i = 0; $i < $cncd["classCount"]; $i++){

		$cncd["objIDs"][] = ui16dec(substr($tagData, $ofst, 2));
		$ofst += 2;
		$cn = read_swf_string(substr($tagData, $ofst));
		$cncd["classNames"][] = $cn;
		$ofst += strlen($cn) + 1;
	}

	return $cncd;

}

/**
 * reads data
 * return an associative array with f9 scene names tag
 */
function read_sceneNameContainer_data($tagData = ""){

	$sncd = array();
	$sncd = read_tag_header_data(substr($tagData, 0, 10));
	$ofst = $sncd["tagSL"];

	$sncd["sceneCount"] = ui16dec(substr($tagData, $ofst, 2));
	$ofst += 2;
	$sncd["sceneNames"] = array();

	for($i = 0; $i < $sncd["sceneCount"]; $i++){
		$sn = read_swf_string(substr($tagData, $ofst));
		$sncd["sceneNames"][] = $sn;
		$ofst += strlen($sn) + 1;
	}

	return $sncd;
}

/**
 * reads data
 * return an associative array with AS3 code fields
 * ???
 */
function read_doAbc2_data($tagData = ""){

	$acd = array();

	return $acd;
}


/**
 * writes data
 * build a productInfo tag data with given associative array
 */
function write_productInfo_data($pid = array()){

}



/**
 * writes data compile f9 class name definitions from
 * a given associative array();
 */
function write_classNameContainer_data($cncd = array()){

	global $swfTagList;
	if(!count($cncd)) return "";

	$tagBody = "";
	$tagBody .= swf_word(count($cncd["classNames"]));

	foreach($cncd["objIDs"] as $cid)
		$tagBody .= swf_word($cid);

	foreach($cncd["classNames"] as $cn)
		$tagBody .= swf_string($cn);

	$tagLength = strlen($tagBody);

	$tagHead = SWFTag_long_header($swfTagList["AS3ClassNames"], $tagLength);

	return $tagHead .$tagBody;
}


/**
 * writes data compile f9 scene names from
 * a given associative array();
 */
function write_sceneNameContainer_data($sncd = array()){

	global $swfTagList;
	if(!count($sncd)) return "";

	$sCount = count($sncd["sceneNames"]);

	$tagBody = "";
	$tagBody .= swf_word($sCount);

	$ids = range(1, $sCount);
	$ids[$sCount - 1] = 0;

	for($i = 0; $i < $sCount; $i++){
		$tagBody .= swf_string($sncd["sceneNames"][$i]);
		$tagBody .= chr($ids[$i]);
	}

	$tagBody .= NIL; // MAYBE this is an end tag NUL character

	$tagLength = strlen($tagBody);

	$tagHead = SWFTag_long_header($swfTagList["AS3SceneNames"], $tagLength);

	return $tagHead .$tagBody;
}

/**
 * writes data
 * return an associative array with AS3 code fields
 * ???
 */
function write_doAbc2_data($acd = array()){

}


?>
